package com.lovo.jpa.dao;

import com.lovo.jpa.dto.StudentDto;
import com.lovo.jpa.entity.MidEntity;
import com.lovo.jpa.entity.StudentEntity;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import java.util.List;
import java.util.Map;

public interface IStudentDao extends CrudRepository<StudentEntity,Long> {

    @Query("select new com.lovo.jpa.dto.StudentDto(mid.student.userName,mid.student.age,mid.teacher.userName) from MidEntity mid " +
            "where mid.teacher.userName=?1")
    public List<StudentDto> findByTeacherName(String teacherName);

    @Query("select new map(mid.student.userName,mid.student.age,mid.teacher.userName) from MidEntity mid " +
            "where mid.teacher.userName=?1")
    public List<Map> findStuMapByTeacherName(String teacherName);



    @Query("select md  from MidEntity md where md.teacher.userName=?1")
    public List<MidEntity>  findAllStuByTeacher(String teacherName);

}
